<jsp:useBean id="db" scope="session" class="com.jipl.Masters.DatabaseBean"/>              
<jsp:setProperty name="db" property="*"/>
<%@ page import="java.io.* ,java.util.*, java.sql.*,com.jipl.login.*"%>


<html xmlns="http://www.w3.org/1999/xhtml">
    <!-- DW6 -->
    <head>

        <title>View Purchase Details</title>

        <script language="JavaScript" type="text/javascript">
            function displayHTML(printContent)
            {
                var int=printContent;
                win=window.open("print.htm",'popup','toolbar=no, status=no');
                win.document.write(int);
                window.print();
            }
            function validate()
            {
                var index1=document.form2.select1.selectedIndex;
                if(index1==0)
                {
                    alert("Please Make a Selection from Supplier Name");
                    document.form2.select1.focus();
                    return false;
                }
            }
        </script>
        <style type="text/css">
            <!--
            .style4 {font-size: 12px}
            .style8 {font-size: 14; color: #FFFFFF; }
            -->
        </style>
        <style type="text/css">
            <!--
            .style10 {color: #FFFFFF}
            .style11 {color: #006600}
            a:link {
                color: #990000;
                text-decoration: none;
            }
            -->
        </style>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link href="../../images/mm_health_nutr.css" rel="stylesheet" type="text/css">
        <style type="text/css">
            <!--
            .style12 {font-size: 12}
            .style13 {color: #4D7920}
            a:visited {
                text-decoration: none;
            }
            a:hover {
                text-decoration: none;
            }
            a:active {
                text-decoration: none;
            }
            .style14 {font-weight: bold}
            -->
        </style>
    </head>
    <body bgcolor="#F4FFE4">
        <table width="102%" border="0" cellspacing="0" cellpadding="0">
            <tr bgcolor="#D5EDB3">
                <td rowspan="2" background="../../images/mm_health_photo copy.jpg">&nbsp;</td>
                <td width="540" height="50" align="center" valign="bottom" nowrap="nowrap" background="../../images/flash_header1.png" class="pageName" id="logo">Stores and Material Management</td>
                <td width="199" background="../../images/flash_header1.png">&nbsp;</td>
            </tr>
            <tr bgcolor="#D5EDB3">
                <td height="49" align="center" valign="top" background="../../images/flash_header2.png" id="tagline">&nbsp;</td>
                <td width="199" background="../../images/flash_header2.png">&nbsp;</td>
            </tr>
            <tr>
                <td colspan="3" bgcolor="#5C743D"></td>
            </tr>
            <tr>
                <td colspan="3" bgcolor="#99CC66" ></td>
            </tr>
            <tr bgcolor="#99CC66">
                <td height="28" background="../../images/flash_menubar.png"><a href="../Entries.jsp"><strong>HOME</strong></a>&nbsp;::&nbsp;<a href="PurchaseHome.jsp"><strong>BACK</strong></a>&nbsp;&nbsp;&nbsp;&nbsp;
                    <script language="JavaScript" type="text/javascript">
                        document.write(TODAY);	</script></td>
                <td height="28" align="center" background="../../images/flash_menubar.png"><span class="style14"><a href="../../masters/Masters.jsp">Masters</a> <a href="../Entries.jsp">Entries</a> <a href="../../reports/AdminReporting.jsp">Reports</a></span></td>
                <td height="28" background="../../images/flash_menubar.png">&nbsp;</td>
            </tr>
            <tr>
                <td colspan="3" bgcolor="#99CC66" ></td>
            </tr>
            <tr>
                <td colspan="3" bgcolor="#5C743D"><img src="../../images/mm_spacer.gif" alt="" width="1" height="2" border="0" /></td>
            </tr>
            <td height="536" colspan="3" align="center" bgcolor="#536A3E">
                <form name="form2" id="form2" action="viewPur.jsp" onSubmit="return validate()">
                    <table width="367" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#DCE7B8">
                        <tr background="images/flash_body.png">
                            <th height="33" colspan="2" background="../../images/flash_header1.png" scope="row">View Purchases </th>
                        </tr>
                        <tr background="images/flash_body.png">
                            <th width="158" background="../../images/flash_body.png" scope="row"><span class="style10">Supplier Name </span></th>
                            <th width="199" nowrap background="../../images/flash_body.png"> <label> </label>

                                <select name="select1">
                                    <option> </option>
                                    <%@ page import="java.io.* , java.util.*, java.sql.*"%>
                                    <%
                                                                    request.getSession(true);
                                                                    String user=session.getAttribute("un").toString();
                      String user_name_query="select distinct(location) from user_reg where uid='"+user+"';";
                            String loc="";
                            ResultSet rs21=db.execSQL(user_name_query);
                            if (rs21.next()==true)
                                            loc=rs21.getString(1);
                            else if(rs21.next()==false)
                                              {
                                                      String qad1="SELECT location FROM admin where un='"+user+"' ";
                                                      ResultSet rst1=db.execSQL(qad1);
                                                      if(rst1.next()==true)
                                                      {
                                                                    loc=rst1.getString(1);
                                                      }
                                              }
                                                                    String q="SELECT distinct(sname) FROM purchase  where location='"+loc+"' and ptype='P'";
                                                                    db.connect();
                                                                    ResultSet rs1=db.execSQL(q);
                                                                            while (rs1.next()==true)
                                                                    {%>
                                    <option><%= rs1.getString(1) %> </option>
                                    <%} %>
                                </select>            </th>
                        </tr>
                        <tr background="images/flash_body.png">
                            <th colspan="2" background="../../images/flash_body.png" scope="row"><label> </label>
                                <input name="Submit" type="submit" class="subHeader" value="View">            </th>
                        </tr>
                    </table>
                </form>
                <%
      if (request.getParameter("Submit")!=null)
      {
      String select= request.getParameter("select1");
      db.connect();

      String qry="SELECT * FROM purchase where sname='"+select+"' and location='"+loc+"'";
      ResultSet rs=db.execSQL(qry);


                %>
                <form id="form1" name="form1">
                    <p>&nbsp;</p>
                    <div align="center">
                        <table width="674" border="1" cellpadding="1" cellspacing="1" bordercolor="#D3E0AA">
                            <tr bgcolor="#000000">
                                <th width="112" height="31" nowrap background="../../images/flash_header1.png" bgcolor="#006600" class="style13 style4">purchase ID </th>
                                <th width="112" nowrap background="../../images/flash_header1.png" bgcolor="#006600"><span class="style8 style12 style13"><span class="style11 style4">Purchase Date</span></span></th>
                                <th width="84" nowrap background="../../images/flash_header1.png" bgcolor="#006600"><span class="style8 style11 style12"><span class="style4 style13">Item Name </span></span></th>
                                <th width="64" nowrap background="../../images/flash_header1.png" bgcolor="#006600"><span class="style8 style11 style12"><span class="style4 style13">Quantity</span></span></th>
                                <th width="35" nowrap background="../../images/flash_header1.png" bgcolor="#006600"><span class="style8 style11 style12"><span class="style4 style13">Rate</span></span></th>
                                <th width="80" nowrap background="../../images/flash_header1.png" bgcolor="#006600"><span class="style8 style11 style12"><span class="style4 style13">Tax (in %) </span></span></th>
                                <th width="101" nowrap background="../../images/flash_header1.png" bgcolor="#006600"><span class="style8 style11 style12"><span class="style4 style13">Value</span></span></th>
                            </tr>
                            <%
                                                       while(rs.next())
                                                       {
                                                       String date=rs.getString(9);
                                                       String[] DateIs=date.split("-");
                                                       String dd=DateIs[2]+"-"+DateIs[1]+"-"+DateIs[0];
                            %>
                            <tr>
                                <th nowrap><div align="left" class="style4 style10"><%=rs.getString(8)%></th>
                                <th nowrap><div align="left" class="style4 style10"><%=dd%></div></th>
                                <th nowrap><div align="left" class="style4 style10"><%=rs.getString(2)%></div></th>
                                <th nowrap><div align="left" class="style4 style10"><%=rs.getString(3)%></div></th>
                                <th nowrap><div align="left" class="style4 style10"><%=rs.getString(4)%></div></th>
                                <th nowrap><div align="left" class="style4 style10"><%=rs.getString(5)%></div></th>
                                <th nowrap><div align="left" class="style4 style10"><%=rs.getString(7)%></div></th>
                            </tr>
                            <% } %>
                        </table>
                    </div>
                    <p align="center">&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                </form>
                <p align="center" class="style10"><a href='javascript:displayHTML(form1.innerHTML)'><strong>Print Privew</strong></a></p>
                <%  }  %>  </tr>
            <tr>
                <td width="259">&nbsp;</td>
                <td width="540">&nbsp;</td>
                <td width="199">&nbsp;</td>
            </tr>
        </table>
    </body>
</html>
